<form id="formEdit" action="save" class="form-horizontal" role="form">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">操作</h4>
			</div>
			<div class="modal-body">

				<!-- 以下为要修改的的内容 -->

				<input type="hidden" name="id"
					data-th-value="${model==null?null:model.id}">

				<div class="form-group">
					<label for="txt_xqks" class="col-sm-3 control-label"><span
						class="text-red">*</span>学期开始时间</label>
					<div class="col-sm-9">
						<input type="text" name="xqks" class="form-control" id="xqks"
							placeholder="学期开始时间" data-th-value="${model==null?'':model.xqks}"
							readonly>
					</div>
				</div>

				<div class="form-group">
					<label for="txt_xqjs" class="col-sm-3 control-label"><span
						class="text-red">*</span>学期结束时间</label>
					<div class="col-sm-9">
						<input type="text" name="xqjs" class="form-control" id="xqjs"
							placeholder="学期结束时间" data-th-value="${model==null?'':model.xqjs}"
							readonly>
					</div>
				</div>


				<!-- 以上为要修改的内容 -->

			</div>
			<div class="modal-footer">
				<button type="submit" class="btn btn-primary">
					<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存
				</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">
					<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭
				</button>
			</div>
		</div>
	</div>
</form>
<script type="text/javascript">
	$(function() {
		laydate.render({
			elem : '#xqks'
		});
		laydate.render({
			elem : '#xqjs'
		});
	});
	var options = {
		message : '验证不通过',
		feedbackIcons : {
			valid : 'glyphicon glyphicon-ok',
			invalid : 'glyphicon glyphicon-remove',
			validating : 'glyphicon glyphicon-refresh'
		},
		fields : {
			xqks : {
				validators : {
					notEmpty : {
						message : '学期开始时间不能为空'
					}
				}
			},
			xqjs : {
				validators : {
					notEmpty : {
						message : '学期结束时间不能为空'
					}
				/* ,
									callback : {
										message : '开始时间必须小于结束时间',
										callback : function(value, validator, $field) {
											let other = validator.getFieldElements(
													'xqks').val();//获得另一个的值

											let start = new Date(other.replace("-", "/")
													.replace("-", "/"));
											let end = new Date(value.replace("-", "/").replace(
													"-", "/"));

											if (start <= end) {
												return true;
											}
											return false;
										}
									} */
				}
			}
		}
	};

	$('#formEdit').bootstrapValidator(options).on('success.form.bv',
			function(e) {
				e.preventDefault(); //很重要没有它则会提交默认表单，不会做下面的ajax表单提交
				var fd = new FormData($("#formEdit")[0]);
				var xqks = new Date($('#xqks').val());
				var xqjs = new Date($('#xqjs').val());
				if (xqks >= xqjs) {
					bootbox.alert('结束时间不能比开始时间早！');
					return;
				}
				$.ajax({
					url : "dictionary/xqsj/save",
					type : "POST",
					data : fd,
					processData : false, // 不处理数据  
					contentType : false, // 不设置内容类型
					success : function(result) {
						if (result.success) {
							$('#myModal').modal("hide");
						} else {
							bootbox.alert(result.msg);
						}
					},
					error : function(result) {
						alert(result);
					}
				});
			});
</script>
